
package com.six.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.six.dao.NewsDaoImpl;
import com.six.dao.NewsTypeDaoImpl;
import com.six.entity.News;
import com.six.entity.NewsType;

import sun.net.www.content.text.plain;

/**
 * ������
 */
@WebServlet("/NewsServlet")
public class NewsServlet extends BaseServlet {
	
    /**
     * @see HttpServlet#HttpServlet()
     * ��ַ��localhost:8080/liuzu/NewsServlet?method=toNews
     */
   
	public void toNews(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//����dao�ɷ�������ȡ����1.�������� 2�����б�
		
		NewsDaoImpl newsDao =new NewsDaoImpl();
		ArrayList<News> listLimit6 =newsDao.getAllLimit6();
		
		
		NewsTypeDaoImpl typeDao =new NewsTypeDaoImpl();
		ArrayList<NewsType> alllist =typeDao.getAllList();
		
		
		req.setAttribute("newsList", listLimit6);
		req.setAttribute("newsTypeList", alllist);
		//��תҳ��
		req.getRequestDispatcher("article_list.jsp").forward(req, resp);
		
	}

/**
 * ͨ����������id��ȡ�����б�
 * ����������ӵ�ʱ�����
 * @param req
 * @param resp
 * @throws ServletException
 * @throws IOException
 */
	public void getNewsByType(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//���ܿͻ��˵Ĳ���,l�������ַ���
		String typeId =req.getParameter("typeId");
		int typeIdInt =0;
		if(typeId!=null && !typeId.equals("")){
			typeIdInt=Integer.valueOf(typeId);
		}
		//����dao�ɷ�������ȡ����1.�������� 2�����б�
		
		NewsDaoImpl newsDao =new NewsDaoImpl();
		ArrayList<News> listByTypeId=newsDao.getListByTypeId(typeIdInt);
		
		NewsTypeDaoImpl typeDao =new NewsTypeDaoImpl();
		ArrayList<NewsType> alllist =typeDao.getAllList();
		
		
		req.setAttribute("newsList", listByTypeId);
		req.setAttribute("newsTypeList", alllist);
		//��תҳ��
		req.getRequestDispatcher("article_list.jsp").forward(req, resp);
		
	}

}
=======
package com.six.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.six.dao.NewsDaoImpl;
import com.six.dao.NewsTypeDaoImpl;
import com.six.entity.News;
import com.six.entity.NewsType;

import sun.net.www.content.text.plain;

/**
 * ������
 */
@WebServlet("/NewsServlet")
public class NewsServlet extends BaseServlet {
	
    /**
     * @see HttpServlet#HttpServlet()
     * ��ַ��localhost:8080/liuzu/NewsServlet?method=toNews
     */
   
	public void toNews(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//����dao�ɷ�������ȡ����1.�������� 2�����б�
		
		NewsDaoImpl newsDao =new NewsDaoImpl();
		ArrayList<News> listLimit6 =newsDao.getAllLimit6();
		
		
		NewsTypeDaoImpl typeDao =new NewsTypeDaoImpl();
		ArrayList<NewsType> alllist =typeDao.getAllList();
		
		
		req.setAttribute("newsList", listLimit6);
		req.setAttribute("newsTypeList", alllist);
		//��תҳ��
		req.getRequestDispatcher("article_list.jsp").forward(req, resp);
		
	}

/**
 * ͨ����������id��ȡ�����б�
 * ����������ӵ�ʱ�����
 * @param req
 * @param resp
 * @throws ServletException
 * @throws IOException
 */
	public void getNewsByType(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//���ܿͻ��˵Ĳ���,l�������ַ���
		String typeId =req.getParameter("typeId");
		int typeIdInt =0;
		if(typeId!=null && !typeId.equals("")){
			typeIdInt=Integer.valueOf(typeId);
		}
		//����dao�ɷ�������ȡ����1.�������� 2�����б�
		
		NewsDaoImpl newsDao =new NewsDaoImpl();
		ArrayList<News> listByTypeId=newsDao.getListByTypeId(typeIdInt);
		
		NewsTypeDaoImpl typeDao =new NewsTypeDaoImpl();
		ArrayList<NewsType> alllist =typeDao.getAllList();
		
		
		req.setAttribute("newsList", listByTypeId);
		req.setAttribute("newsTypeList", alllist);
		//��תҳ��
		req.getRequestDispatcher("article_list.jsp").forward(req, resp);
		
	}

}
